﻿using System.Collections.Generic;

namespace MathService.DSP.Signals
{
    public static class DigitalSignalExtentions
    {
        #region Массивы

        public static void Set_dx(this DigitalSignal[] Signals, double dx)
        {
            DigitalSignal.Set_dx(dx, Signals);
        }

        public static void Set_x0(this DigitalSignal[] Signals, double x0)
        {
            DigitalSignal.Set_x0(x0, Signals);
        }

        public static void Align(this DigitalSignal[] Signals)
        {
            DigitalSignal.AlignSignals(Signals);
        }

        // ReSharper disable MemberCanBePrivate.Global
        public static DigitalSignal Concatinate(this DigitalSignal[] Signals)
        // ReSharper restore MemberCanBePrivate.Global
        {
            var SamplesCount = 0;
            var SignalsCount = Signals.Length;
            for(var i = 0; i < SignalsCount; i++)
                SamplesCount += Signals[i].SamplesCount;

            var Result = new DigitalSignal(Signals[0].dx, Signals[0].x0, SamplesCount);
            var n = 0;
            for(var i = 0; i < SignalsCount && n < SamplesCount; i++)
            {
                var j_Length = Signals[i].SamplesCount;
                for(var j = 0; j < j_Length; j++)
                    Result[n++] = Signals[i][j];
            }
            return Result;
        }

        public static DigitalSignal Concatinate(this List<DigitalSignal> Signals)
        {
            return Signals.ToArray().Concatinate();
        }

        // ReSharper disable MemberCanBePrivate.Global
        public static DigitalSignal Summ(this DigitalSignal[] Signals)
        // ReSharper restore MemberCanBePrivate.Global
        {
            DigitalSignal Result = null;

            var i_Length = Signals.Length;
            for(var i = 0; i < i_Length; i++)
                Result += Signals[i];

            return Result;
        }

        public static DigitalSignal Summ(this List<DigitalSignal> Signals)
        {
            return Signals.ToArray().Summ();
        }

        #endregion
    }
}

